<template>
    <div>
        <van-swipe-cell v-for="(item,index) of empList" :key="index">
            <div class="item">
                <!-- <van-col span="6"> -->
                    <img :src="item.portrait">
                <!-- </van-col> -->
                <van-col span="8">{{item.name}}</van-col>
                <van-col span="8">{{item.phone}}</van-col>
                <van-col span="4">
                    <i class="iconfont" :class="item.is_adopt == 1?'icon-bangding3':'icon-quxiaobangding'"></i>
                </van-col>
            </div>
            <template #right>
                <van-button square type="danger" class="disable-btn" v-if="userInfo.role_type == 1" text="解绑" @click="unbind(item.id)"/>
                <van-button square type="primary" class="disable-btn" v-if="userInfo.role_type == 1" :text="item.is_adopt == 1?'取消审核':'通过审核'" @click="check(item.id,item.is_adopt)"/>
            </template>
        </van-swipe-cell>
    </div>
</template>
<script>
import {EmployeeList,IsAdopt,RelieveEmployee} from '../ajax'
import { Toast,Dialog } from 'vant';
export default {
    data() {
        return {
            empList:[],
            userInfo:{}
        }
    },
    created(){
        this.getEmployeeList();
        this.userInfo=this.$store.getters.wxUserInfo;
    },
    methods:{
        check(id,is_adopt){
            const data = {
                id,
                uid:this.$store.getters.wxUserInfo.id,
                is_adopt:is_adopt == 1?2:1
            }
            IsAdopt(data).then(res=>{
                Toast('审核成功');
                this.getEmployeeList();
            })
        },
        getEmployeeList(){
            const data = {
                uid:this.$store.getters.wxUserInfo.id,
                group_id:this.$store.getters.wxUserInfo.group_id
            }
            EmployeeList(data).then(res=>{
                console.log(res);
                this.empList = res;
            })
        },
        unbind(id){
            Dialog.confirm({
                title: '解绑确认',
                message: '确认解绑后该员工将不属于该公司管辖,请谨慎操作!',
            })
            .then(() => {
                const data = {
                    id
                }
                RelieveEmployee(data).then(res=>{
                    console.log(res);
                    Toast('解绑成功');
                    this.getEmployeeList();
                })
            })
        }
    }
}
</script>
<style lang="scss" scoped>
    .item{
        text-align: center;
        height: 5rem;
        line-height: 5rem;
        border-bottom: 1px solid #eee;
        margin:0 1rem;
        img{
            width: 3rem;
            height: 3rem;
            margin: 1rem 0;
            float: left;
            border-radius: 50%;
        }
        :last-child{
            text-align: right;
            font-size: 1.4rem;
            color: #888;
        }
    }
    .disable-btn{
            height: 100% !important;
        }
</style>